// #include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;

#define INF 0x3f3f3f3f

struct Tree{
    const static int N = 20020;
    struct edge{
        int to, nxt;
    }e[N << 1];
    int head[N], size[N], vis[N];
    int n, len, max_subtree_size, center;

    Tree(){
        n = 0; len = 0; max_subtree_size = INF;
        memset(head, 0, sizeof(head)); 
        memset(size, 0, sizeof(size)); 
        memset(vis, 0, sizeof(vis)); 
    }

    void init(){
        n = 0; len = 0; max_subtree_size = INF;
        memset(head, 0, sizeof(head)); 
        memset(size, 0, sizeof(size)); 
        memset(vis, 0, sizeof(vis)); 
        return ;
    }

    void add_edge(int u, int v){
        e[++len].to = v; e[len].nxt = head[u]; head[u] = len; return ;
    }

    void insert_edge(int u, int v){
        add_edge(u, v); add_edge(v, u);
    }

    void dfs_get_center(int cur){
        int i, max_part = 0;
        vis[cur] = size[cur] = 1;
        for(i = head[cur]; i; i = e[i].nxt){
            int v = e[i].to;
            if(vis[v]) continue;
            dfs_get_center(v);
            size[cur] += size[v];
            max_part = max(size[v], max_part);
        }
        max_part = max(n - size[cur], max_part);
        if(max_subtree_size > max_part){
            max_subtree_size = max_part;
            center = cur;
        }
        return ;
    }
}tree;

int main(){
    int T;
    cin>>T;
    while(T--){
        tree.init();
        scanf("%d", &tree.n);
        for(int i = 1; i < tree.n; i++){
            int u, v;
            scanf("%d%d", &u, &v);
            tree.insert_edge(u, v);
        }
        tree.dfs_get_center(1);
        printf("%d %d\n", tree.center, tree.max_subtree_size);
    }

    return 0;
}